<template>
	<div class="user-page">
		<!--查询表单-->
		<el-card class="box-card mb10" shadow="never">
			<el-form ref="searchFormRef" class="search-form" :inline="true" label-position="left" label-width="75px" :model="searchForm">
				<el-row :gutter="30" justify="start">
					<el-col :span="6">
						<el-form-item class="form-item" label="表单名称:" prop="name">
							<el-input v-model="searchForm.name" placeholder="请输入表单名称" />
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item class="form-item" label="表单类型:" prop="type">
							<el-select v-model="searchForm.type" class="el-form-item" clearable placeholder="请选择表单类型">
								<el-option label="静态" value="1" />
								<el-option label="动态" value="2" />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<div class="search-btn">
							<el-button type="primary" @click="handleSearch">查询</el-button>
							<el-button @click="handleReset">重置</el-button>
						</div>
					</el-col>
				</el-row>
			</el-form>
		</el-card>
		<el-card class="box-card" shadow="never">
			<static-table :tableData="tableData" rowId="configId" :loading="loading" :seqConfig="{ startIndex: (pageNum - 1) * pageSize }">
				<template #vux-search>
					<el-row :gutter="12" class="mb10">
						<el-button class="ml8" type="primary" v-has="'handle:workflow:form:add'" @click="handleAdd">
							<el-icon><ele-Plus /></el-icon>
							&nbsp;新增
						</el-button>
					</el-row>
				</template>
				<template #vux-column>
					<vxe-column type="seq" title="序号" width="60" />
					<vxe-column field="name" min-width="150" show-overflow="tooltip" title="表单名称" />
					<vxe-column field="remark" min-width="200" show-overflow="tooltip" title="备注" />
					<vxe-column field="type" min-width="120" title="表单类型">
						<template #default="{ row }">
							<span>{{ row.type == '1' ? '静态' : '动态' }}</span>
						</template>
					</vxe-column>
					<vxe-column field="createTime" min-width="150" title="创建时间" />

					<vxe-column field="operation" fixed="right" min-width="120" title="操作">
						<template #default="{ row }">
							<div class="vxe-action">
								<a @click="handleUpdate(row)" v-has="'handle:workflow:form:update'">修改</a>
								<a @click="handleDelete(row)" v-has="'handle:workflow:form:delete'">删除</a>
								<a @click="handleDesgin(row)" v-if="row.type == 2" v-has="'handle:workflow:form:desgin'">设计</a>
								<span style="color: grey; margin-left: 15px" v-else v-has="'handle:workflow:form:desgin'">设计</span>
							</div>
						</template>
					</vxe-column>
				</template>
			</static-table>
			<el-pagination background :current-page="pageNum" :layout="layout" :page-size="pageSize" :total="dataCount" @current-change="handleCurrentChange" @size-change="handleSizeChange" />
		</el-card>
		<EditFormModal ref="editModalRef" @peak-modal-ok="handleModalOk" />
		<DesginFormModal ref="desginFormModalRef" />
	</div>
</template>
<script name="ParamsManage" setup>
import global from '@/utils/global'
import useTableList from '@/hooks/useTableList'
import useModal from '@/hooks/useModal'
const EditFormModal = defineAsyncComponent(() => import('./leafPages/EditFormModal.vue'))
const DesginFormModal = defineAsyncComponent(() => import('./leafPages/DesginFormModal.vue'))

/*
 *@Description: 状态初始化
 *@MethodAuthor: liuYuFeng
 *@Date: 2023-08-28 10:11:35
 */

const state = reactive({
	searchForm: {
		name: '',
		type: '',
	},
	searchFormRef: null,
	desginFormModalRef: null,
})
const { searchForm, searchFormRef, desginFormModalRef } = toRefs(state)

const queryUrl = '/sop-joint-disposal/web/v1/form/list'
const { loading, dataCount, handleInitQuery, handleModalOk, tableData, pageNum, pageSize, layout, handleSizeChange, handleCurrentChange } = useTableList(queryUrl, state.searchForm)

const { editModalRef, handleAdd, handleUpdate } = useModal()

/*
 *@Description: 方法模块
 *@MethodAuthor: liuYuFeng
 *@Date: 2023-08-28 10:16:03
 */
const handleDesgin = row => {
	state.desginFormModalRef.handleShowModal(row)
}
const handleSearch = () => {
	handleInitQuery()
}
const handleReset = () => {
	state.searchFormRef.resetFields()
	handleInitQuery()
}
const handleDelete = row => {
	global.$baseConfirm(
		row ? `是否确认删除名称为"--【${row.name}】--"的数据?` : '是否确认删除当前选中的数据？',
		'提示',
		() => {
			global.$fetchPostData(`/sop-joint-disposal/web/v1/form/remove`, { removeIdList: [row.id] }).then(data => {
				if (data.code == 200) {
					global.$baseMessage(data.msg, 'success')
					handleModalOk(2)
				} else {
					global.$baseMessage(data.msg, 'error')
				}
			})
		},
		() => {}
	)
}
</script>
<style lang="scss" scoped></style>
